<?php
set_time_limit(0);
error_reporting(E_ALL);
 
require_once '../c/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();

$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '姓名')
            ->setCellValue('B1', '电话')
            ->setCellValue('C1', '电子邮箱')
            ->setCellValue('D1', '学生证')
            ->setCellValue('E1', '分数')
            ->setCellValue('F1', '年级')
            ->setCellValue('G1', '选区')
            ->setCellValue('H1', '所在学校')
            ->setCellValue('I1', '参与时间')
;
include '../c/config.php';

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}


$getNianji=3;
if (isset($_GET['n'])){
    $getNianji=$_GET['n'];
}
$ZW_nj=array(3=>'三',4=>'四',5=>'五',6=>'六');
$fileName='其他-'.$ZW_nj[$getNianji].'年级';

$sql="SELECT * FROM `u3` WHERE `fxqu` LIKE '其他' and nianji=".$getNianji."  order by fen desc";
$query =$mysqli->query($sql);
$index=2;
while ($list=$query->fetch_array()){
	    $objPHPExcel->setActiveSheetIndex(0)
	    ->setCellValue('A'.$index, $list['name'])
	    ->setCellValue('B'.$index, $list['phone'])
	    ->setCellValue('C'.$index, $list['email'])
	    ->setCellValue('D'.$index, $list['hao'].' ')
	    ->setCellValue('E'.$index, $list['fen'])
	    ->setCellValue('F'.$index, $ZW_nj[$list['nianji']].'年级')
	    ->setCellValue('G'.$index, $list['szqu'].' '.$list['fxqu'])
	    ->setCellValue('H'.$index, $list['school'].$list['school2'])
	    ->setCellValue('I'.$index, $list['createtime'])
	    ;
	   
	    $index++;
	  
    
}
 
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('学生考试信息');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename='.$fileName.'.xlsx');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
